package com.css.fxfzysx.modules.vaolEngineering.service.impl;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.constants.FxfzConstants;
import com.css.fxfzysx.modules.cztDataMange.result.ParsingResult;
import com.css.fxfzysx.modules.lifeline.annotation.ValidationProcessor;
import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxMainTableEntity;
import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxUpNetworkEntity;
import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxVersionEntity;
import com.css.fxfzysx.modules.lifeline.repository.LifelineEngineeringRepository;
import com.css.fxfzysx.modules.lifeline.utils.ShpUtils;
import com.css.fxfzysx.modules.vaolEngineering.dto.DataValidation1Dto;
import com.css.fxfzysx.modules.vaolEngineering.dto.DataValidation2Dto;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork1Param;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork2Param;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork3Param;
import com.css.fxfzysx.modules.vaolEngineering.repository.UpNetworkRepository;
import com.css.fxfzysx.modules.vaolEngineering.service.UpNetworkService;
import com.css.fxfzysx.modules.vaolEngineering.utils.CheckUtil;
import com.css.fxfzysx.modules.vaolEngineering.utils.MainTableUtils;
import com.css.fxfzysx.modules.vaolEngineering.vo.importVo.ContinuousWeldingImportVo;
import com.css.fxfzysx.modules.vaolEngineering.vo.importVo.InterfaceWeldingImportVo;
import com.css.fxfzysx.modules.vaolEngineering.vo.importVo.PipelineDamageRateImportVo;
import com.css.fxfzysx.util.PlatformDateUtils;
import com.css.fxfzysx.util.PlatformObjectUtils;
import com.css.fxfzysx.util.ShpAnalyticUtil;
import com.css.fxfzysx.util.UUIDGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

@Service
@Slf4j
public class UpNetworkServiceImpl implements UpNetworkService {

    @Autowired
    private UpNetworkRepository upNetworkRepository;

    @Autowired
    private ShpUtils shpUtils;

    @Autowired
    private MainTableUtils mainTableUtils;

    @Autowired
    private LifelineEngineeringRepository lifelineEngineeringRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void countPseVulnerability(String versionId, String tableId) {
        List<SmxUpNetworkEntity> list = new ArrayList<>();
        if (PlatformObjectUtils.isNotEmpty(tableId)) {
            SmxUpNetworkEntity entity = upNetworkRepository.getByTableId(tableId);
            list.add(entity);
        } else {
            list = upNetworkRepository.getByVersionId(versionId);
        }
        list.forEach(it -> {
            it.setDisasterRate6State(getDestructiveState(it.getDisasterRate6()));
            if (PlatformObjectUtils.isEmpty(it.getDisasterRate6State())) {
                it.setDisasterRate6StateCorrect(it.getDisasterRate6State());
            }
            it.setDisasterRate7State(getDestructiveState(it.getDisasterRate7()));
            if (PlatformObjectUtils.isEmpty(it.getDisasterRate7State())) {
                it.setDisasterRate7StateCorrect(it.getDisasterRate7State());
            }
            it.setDisasterRate8State(getDestructiveState(it.getDisasterRate8()));
            if (PlatformObjectUtils.isEmpty(it.getDisasterRate8State())) {
                it.setDisasterRate8StateCorrect(it.getDisasterRate8State());
            }

            it.setDisasterRate9State(getDestructiveState(it.getDisasterRate9()));
            if (PlatformObjectUtils.isEmpty(it.getDisasterRate9State())) {
                it.setDisasterRate9StateCorrect(it.getDisasterRate9State());
            }
            it.setDisasterRate10State(getDestructiveState(it.getDisasterRate10()));
            if (PlatformObjectUtils.isEmpty(it.getDisasterRate10State())) {
                it.setDisasterRate10StateCorrect(it.getDisasterRate10State());
            }
            upNetworkRepository.savePseVulnerabilityResult(it);
            if (PlatformObjectUtils.isEmpty(tableId)) {
                mainTableUtils.updateCalculationStatus(it.getTableId(),it.getDisasterRate6State(),it.getDisasterRate7State(),it.getDisasterRate8State(),it.getDisasterRate9State(),it.getDisasterRate10State(), 1);
            }
        });
        if (PlatformObjectUtils.isNotEmpty(list.get(0).getLxBreakState()) && PlatformObjectUtils.isNotEmpty(list.get(0).getJkDamage())) {
            mainTableUtils.updateVersionCalculationStatus(versionId, 0);
        }
    }

    public String getDestructiveState(BigDecimal a) {
        if (a.compareTo(new BigDecimal(0)) == 0) {
            return "基本完好";
        } else if (a.compareTo(new BigDecimal(0)) > 0 && a.compareTo(new BigDecimal(2)) < 1) {
            return "轻微破坏";
        } else if (a.compareTo(new BigDecimal(2)) > 0 && a.compareTo(new BigDecimal(5)) < 1) {
            return "中等破坏";
        } else if (a.compareTo(new BigDecimal(5)) > 0 && a.compareTo(new BigDecimal(12)) < 1) {
            return "严重破坏";
        } else {
            return "毁坏";
        }
    }

    @Override
    public RestResponse countContinuousWelding(String versionId, String tableId) {
        try {
            List<SmxUpNetworkEntity> networkList = new ArrayList<>();
            if (PlatformObjectUtils.isNotEmpty(tableId)) {
                SmxUpNetworkEntity entity = upNetworkRepository.getByTableId(tableId);
                networkList.add(entity);
            } else {
                networkList = upNetworkRepository.getByVersionId(versionId);
            }
            for (SmxUpNetworkEntity cw : networkList) {
                //表格1   最大管线应变
                BigDecimal result1 = cw.getMaxSpeed().divide(cw.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                        .add(cw.getMaxAccelaration().multiply(cw.getDiameter()).divide(BigDecimal.valueOf(2)
                                .multiply(cw.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

                BigDecimal result2 = cw.getMaxSpeed().negate().divide(cw.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                        .add(cw.getMaxAccelaration().multiply(cw.getDiameter()).divide(BigDecimal.valueOf(2)
                                .multiply(cw.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

                BigDecimal result3 = cw.getMaxSpeed().divide(cw.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                        .subtract(cw.getMaxAccelaration().multiply(cw.getDiameter()).divide(BigDecimal.valueOf(2)
                                .multiply(cw.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

                BigDecimal result4 = cw.getMaxSpeed().negate().divide(cw.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                        .subtract(cw.getMaxAccelaration().multiply(cw.getDiameter()).divide(BigDecimal.valueOf(2)
                                .multiply(cw.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

                ArrayList<BigDecimal> list = new ArrayList<>();
                list.add(result1);
                list.add(result2);
                list.add(result3);
                list.add(result4);
                cw.setMaxPipelineStrain(list.stream().filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(new BigDecimal(0)));

                //表格2   l'
                BigDecimal cos = BigDecimal.valueOf(Math.cos(Math.toRadians(cw.getEarthquakewaveIncidentAngle().doubleValue()))).setScale(4, RoundingMode.HALF_UP);
                BigDecimal lCos = cw.getEarthquakeWavelength().divide(cos, 4, RoundingMode.HALF_UP);
                cw.setLCos(lCos);

                //s
                BigDecimal s = BigDecimal.valueOf(1).divide(BigDecimal.valueOf(1).add(cw.getElasticityModulus().multiply(cw.getCrossSectionalArea()).divide(cw.getFoundationZCoefficient(), 4, BigDecimal.ROUND_HALF_UP)
                        .multiply(BigDecimal.valueOf(2).multiply(BigDecimal.valueOf(Math.PI))
                                .divide(cw.getLCos(), 4, RoundingMode.HALF_UP).pow(2))), 4, RoundingMode.HALF_UP);
                cw.setS(s);

                //ep
                BigDecimal ep = cw.getMaxPipelineStrain().multiply(cw.getS()).setScale(4, RoundingMode.HALF_UP);
                cw.setEp(ep);

                //zdyl
                BigDecimal zdyl = cw.getEp().multiply(cw.getElasticityModulus()).setScale(4, RoundingMode.HALF_UP);
                cw.setZdyl(zdyl);

                //表格3   //弯曲段产生的剪力
                BigDecimal wqdcsdjl = cw.getMaxPipelineStrain().multiply(cw.getElasticityModulus()).subtract(cw.getSoilbulkDensity1()).multiply(cw.getBurialDepth()).setScale(4, RoundingMode.HALF_UP);
                cw.setWqdcsdjl(wqdcsdjl);

                //弯矩
                BigDecimal wj = cw.getWqdcsdjl().divide((new BigDecimal(3).multiply(cw.getSoilstaticPressureCoefficient())), 4, RoundingMode.HALF_UP);
                cw.setWj(wj);

                //i
                BigDecimal i = cw.getPipeOd().divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
                cw.setI(i);

                //ipai
                BigDecimal ipai = BigDecimal.valueOf(Math.PI).multiply(cw.getPipeOd().pow(4)).divide(BigDecimal.valueOf(64), 4, RoundingMode.HALF_UP)
                        .subtract(BigDecimal.valueOf(Math.PI).multiply(cw.getInsideDiameter().pow(4)).divide(BigDecimal.valueOf(64), 4, RoundingMode.HALF_UP));

                if (ipai.compareTo(new BigDecimal(0)) == 0) {
                    return RestResponse.fail("{d1 管道外径}和{d2 管道内径}的值不能相等!");
                }
                cw.setIpai(ipai);

                //弯曲段弯曲应力（轴向）
                BigDecimal wqylZx = cw.getI().multiply((cw.getWj()).divide(cw.getIpai(), 4, RoundingMode.HALF_UP));
                cw.setWqylZx(wqylZx);

                //弯曲段的剪应力（环向）
                BigDecimal jylHx = cw.getWqdcsdjl().divide(cw.getCrossSectionalArea(), 4, RoundingMode.HALF_UP);
                cw.setJylHx(jylHx);

                //表格4   T型接头处产生的剪力Q
                BigDecimal txjtcjyl = cw.getMaxPipelineStrain().multiply(cw.getElasticityModulus()).multiply(cw.getCrossSectionalArea())
                        .subtract(cw.getSoilbulkDensity1()).multiply(cw.getTBuriedDepth()).setScale(4, RoundingMode.HALF_UP);
                cw.setTxjtcjyl(txjtcjyl.divide(BigDecimal.valueOf(2), 4, RoundingMode.HALF_UP));

                //弯矩M
                BigDecimal wjT = cw.getTxjtcjyl().divide((new BigDecimal(2)).multiply(cw.getSoilstaticPressureCoefficient()), 4, RoundingMode.HALF_UP);
                cw.setWjT(wjT);

                //T型段的正应力（轴向）
                BigDecimal zylZxT = cw.getWjT().multiply(cw.getDiameter()).divide((new BigDecimal(2).multiply(cw.getIpai())), 4, RoundingMode.HALF_UP);
                cw.setZylZxT(zylZxT);

                //T型段的剪应力（环向）
                BigDecimal jylHxT = cw.getTxjtcjyl().divide(cw.getCrossSectionalArea(), 4, RoundingMode.HALF_UP);
                cw.setJylHxT(jylHxT);

                //表格5   温度引起的温度应力
                BigDecimal wdyl = cw.getElasticityModulus().multiply(cw.getLinearExpansionCoefficient()).multiply(cw.getCorrectionFactor()).multiply(cw.getTemperatureDifference()).setScale(4, BigDecimal.ROUND_HALF_UP);
                cw.setWdyl(wdyl);

                //表格6    环向拉应力
                //管壁厚度  （d1-d2）/2
                BigDecimal wallThickness = (cw.getPipeOd().subtract(cw.getInsideDiameter())).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
                cw.setWallThickness(wallThickness);

                BigDecimal hxlyl = cw.getInternalPressure().multiply(cw.getDiameter()).divide((new BigDecimal(2).multiply(cw.getWallThickness())), 4, RoundingMode.HALF_UP);
                cw.setHxlyl(hxlyl);

                //纵向拉应力
                BigDecimal zxlyl = (cw.getDiameter().multiply(cw.getInternalPressure()).divide((new BigDecimal(2)
                        .multiply(cw.getWallThickness())), 4, RoundingMode.HALF_UP)).multiply(cw.getCurvature());
                cw.setZxlyl(zxlyl);

                //表格7  土静压力
                BigDecimal ps = (new BigDecimal(1).add(cw.getSoilLateralPressure())).multiply(cw.getSoilbulkDensity2()).multiply(cw.getSoilBurialDepth()).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
                cw.setPs(ps);


                //环向压应力
                BigDecimal hxyyl = cw.getPs().multiply(cw.getDiameter()).divide((new BigDecimal(2).multiply(cw.getWallThickness())), 4, RoundingMode.HALF_UP);
                cw.setHxyyl(hxyyl);

                //纵向压应力
                BigDecimal zxyyl = cw.getPoissonsRatio().multiply(cw.getHxyyl()).setScale(4, RoundingMode.HALF_UP);
                cw.setZxyyl(zxyyl);

                //表格8   所有轴向应力之和a1
                BigDecimal allSumZx = cw.getEp().add(cw.getWqylZx()).add(cw.getZylZxT()).add(cw.getZxyyl()).add(cw.getWdyl().add(cw.getZxlyl())).setScale(4, BigDecimal.ROUND_HALF_UP);
                cw.setAllSumZx(allSumZx);

                //表格9  所有轴向应力之和a2
                BigDecimal allSumHx = cw.getJylHx().add(cw.getJylHxT()).add(cw.getHxlyl()).add(cw.getHxyyl()).setScale(4, RoundingMode.HALF_UP);
                cw.setAllSumHx(allSumHx);

                //表格10   许用应力
                BigDecimal subtract = cw.getAllSumZx().subtract(cw.getAllSumHx());
                BigDecimal permissibleStress = BigDecimal.valueOf(Math.abs(subtract.doubleValue()));
                cw.setPermissibleTress(permissibleStress);

                if (PlatformObjectUtils.isEmpty(cw.getPermissibleTressCorrect())) {
                    cw.setPermissibleTressCorrect(permissibleStress);
                }

                BigDecimal ar = cw.getYieldLimitStress().multiply(cw.getAdjustmentCoefficient1());
                BigDecimal ab = cw.getStrengthLimitStress().multiply(cw.getAdjustmentCoefficient2());

                if (cw.getPermissibleTress().compareTo(ar) < 0) {
                    cw.setLxBreakState("基本完好");
                    cw.setLxBreakStateCorrect("基本完好");
                } else if (ar.compareTo(cw.getPermissibleTress()) < 0 || ar.compareTo(cw.getPermissibleTress()) == 0
                        && cw.getPermissibleTress().compareTo(ab) < 0 || cw.getPermissibleTress().compareTo(ab) == 0) {
                    cw.setLxBreakState("中等破坏");
                    cw.setLxBreakStateCorrect("中等破坏");
                } else if (cw.getPermissibleTress().compareTo(ab) > 0) {
                    cw.setLxBreakState("破坏");
                    cw.setLxBreakStateCorrect("破坏");
                }

                if (cw.getPermissibleTressCorrect().compareTo(ar) < 0) {
                    cw.setLxBreakStateCorrect("基本完好");
                } else if (ar.compareTo(cw.getPermissibleTressCorrect()) < 0 || ar.compareTo(cw.getPermissibleTressCorrect()) == 0
                        && cw.getPermissibleTressCorrect().compareTo(ab) < 0 || cw.getPermissibleTressCorrect().compareTo(ab) == 0) {
                    cw.setLxBreakStateCorrect("中等破坏");
                } else if (cw.getPermissibleTressCorrect().compareTo(ab) > 0) {
                    cw.setLxBreakStateCorrect("破坏");
                }
                upNetworkRepository.saveContinuousWeldingResult(cw);
                if (PlatformObjectUtils.isEmpty(tableId)) {
                    mainTableUtils.updateUpNetCalculationStatus(cw.getTableId(), 1);
                }
            }
            if (PlatformObjectUtils.isNotEmpty(networkList.get(0).getDisasterRate6()) && PlatformObjectUtils.isNotEmpty(networkList.get(0).getJkDamage())) {
                mainTableUtils.updateVersionCalculationStatus(versionId, 0);
            }
            return RestResponse.succeed("计算成功!");
        } catch (Exception e) {
            log.error("error:{}", e.getMessage(), e);
            return RestResponse.fail("数据异常,计算失败!");
        }
    }

    @Override
    public RestResponse countInterfaceWelding(String versionId, String tableId) {
        try {
            List<SmxUpNetworkEntity> list = new ArrayList<>();
            if (PlatformObjectUtils.isNotEmpty(tableId)) {
                SmxUpNetworkEntity entity = upNetworkRepository.getByTableId(tableId);
                list.add(entity);
            } else {
                list = upNetworkRepository.getByVersionId(versionId);
            }
            list.forEach(ie -> {
                //表格1
                BigDecimal lcos = ie.getEarthquakeWavelength().divide(BigDecimal.valueOf(Math.cos(Math.toRadians(ie.getEarthquakewaveIncidentAngle().doubleValue()))), 4, RoundingMode.HALF_UP);

                ie.setJkLCos(lcos);


                BigDecimal result = BigDecimal.valueOf(1).divide(BigDecimal.valueOf(1).add(ie.getElasticityModulus().multiply(ie.getCrossSectionalArea())
                        .divide(ie.getFoundationZCoefficient(), 4, RoundingMode.HALF_UP)
                        .multiply(BigDecimal.valueOf(2).multiply(BigDecimal.valueOf(Math.PI)).divide(ie.getJkLCos(), 4, RoundingMode.HALF_UP).pow(2))), 4, RoundingMode.HALF_UP);

                ie.setResult(result);

                //ER
                BigDecimal er = ie.getGroundMotionSpeed().divide(ie.getSurfaceWaveVelocity(), 4, RoundingMode.HALF_UP);
                ie.setEr(er);

                //管道轴向应变量幅值
                BigDecimal et = ie.getEr().multiply(result);
                ie.setEt(et);

                //LT
                BigDecimal lt = ie.getInterfaceReductionCoefficient().multiply(ie.getSinglePipeLength()).multiply(ie.getEt());
                ie.setLt(lt);


                //表格2  ps
                BigDecimal ps = (new BigDecimal(1).add(ie.getSoilPressure())).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP).multiply(ie.getSoilbulkDensity2()).multiply(ie.getDepth()).setScale(4, RoundingMode.HALF_UP);
                ie.setJkPs(ps);

                //es
                BigDecimal es = (ie.getJkPs().multiply(ie.getPipeOd()).multiply(ie.getCurvature())).divide((new BigDecimal(2)).multiply(ie.getSoilbulkDensity2()), 4, RoundingMode.HALF_UP).multiply((new BigDecimal(1).divide(ie.getElasticityModulus(), 4, RoundingMode.HALF_UP)));
                ie.setEs(es);

                //压缩变形
                BigDecimal compressDeform = ie.getEs().multiply(ie.getSinglePipeLength()).setScale(4, RoundingMode.HALF_UP);
                ie.setCompressDeform(compressDeform);

                //表格3    拉伸应变
                BigDecimal tensileStrain = (ie.getInternalWaterPressure().multiply(ie.getPipeOd()).multiply(ie.getCurvature())).
                        divide(new BigDecimal(2).multiply(ie.getThickness()), 4, RoundingMode.HALF_UP).multiply((new BigDecimal(1).divide(ie.getElasticityModulus(), 4, RoundingMode.HALF_UP))).setScale(4, RoundingMode.HALF_UP);
                ie.setTensileStrain(tensileStrain);

                //拉伸变形
                BigDecimal strainDeform = ie.getTensileStrain().multiply(ie.getSinglePipeLength()).setScale(4, RoundingMode.HALF_UP);
                ie.setStrainDeform(strainDeform);

                //组合轴向拉伸
                BigDecimal combineAxialStrain = ie.getLt().add(ie.getCompressDeform()).add(ie.getStrainDeform()).setScale(4, RoundingMode.HALF_UP);
                ie.setCombineAxialStrain(combineAxialStrain);

                if (PlatformObjectUtils.isEmpty(ie.getCombineAxialStrainCorrect())) {
                    ie.setCombineAxialStrainCorrect(combineAxialStrain);
                }

                BigDecimal val = ie.getAllowableElongation();
                if (combineAxialStrain.compareTo(val) < 0) {
                    ie.setJkDamage("轻微破坏");
                } else {
                    int i = combineAxialStrain.compareTo(new BigDecimal(2).multiply(val));
                    if (val.compareTo(combineAxialStrain) < 0
                            && i < 0) {
                        ie.setJkDamage("中等破坏");
                    } else if (i > 0) {
                        ie.setJkDamage("破坏");
                    }
                }

                BigDecimal combineAxialStrainCorrect = ie.getCombineAxialStrainCorrect();
                if (combineAxialStrainCorrect.compareTo(val) < 0) {
                    ie.setJkDamageCorrect("轻微破坏");
                } else {
                    int i = combineAxialStrainCorrect.compareTo(new BigDecimal(2).multiply(val));
                    if (val.compareTo(combineAxialStrainCorrect) < 0
                            && i < 0) {
                        ie.setJkDamageCorrect("中等破坏");
                    } else if (i > 0) {
                        ie.setJkDamageCorrect("破坏");
                    }
                }
                upNetworkRepository.saveInterfaceWeldingResult(ie);
                mainTableUtils.updateUpNetCalculationStatus(ie.getTableId(), 1);
            });
            if (PlatformObjectUtils.isNotEmpty(list.get(0).getDisasterRate6()) && PlatformObjectUtils.isNotEmpty(list.get(0).getLxBreakState())) {
                mainTableUtils.updateVersionCalculationStatus(versionId, 0);
            }
            return RestResponse.succeed("计算成功!");
        } catch (Exception e) {
            String message = "数据异常,计算失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse importPipelineDamageRate(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            String titleName = "[场地分类, 烈度, 灰口铸铁管, 水泥管, 钢管, 球墨铸铁管, PVC管, PE管, PPR管]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = CheckUtil.check(2, read.size(), read, titleName);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<PipelineDamageRateImportVo> dataList = new ArrayList<>();
            read.forEach(it -> {
                PipelineDamageRateImportVo entity = new PipelineDamageRateImportVo();
                entity.setSite(it.get(0).toString());
                entity.setIntensity(it.get(1).toString());
                entity.setGreyIronPipe(new BigDecimal(it.get(2).toString()));
                entity.setCementPipe(new BigDecimal(it.get(3).toString()));
                entity.setSteelPipe(new BigDecimal(it.get(4).toString()));
                entity.setDuctileIronPipe(new BigDecimal(it.get(5).toString()));
                entity.setPvcPipe(new BigDecimal(it.get(5).toString()));
                entity.setPePipe(new BigDecimal(it.get(5).toString()));
                entity.setPprPipe(new BigDecimal(it.get(5).toString()));
                dataList.add(entity);
            });
            return RestResponse.succeed(dataList);
        } catch (IOException e) {
            String message = "数据异常,导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse importContinuousWelding(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            String titleName = "[Vmax最大地面速度（m/s）, αmax 最大地面速度（m/s^2）, D管道直径 (m), Cp纵波波速（m/s）, Cs横波波速（m/s）, E管材弹性模量（N/m^2), F管道横截面积（m^2）, K地基系数（N/m^2), L地震波长(m), Ф地震波入射角(°), μ管材泊桑比, tu土容重参数, Lj管埋藏深度计算系数, 土静压系数, d1管道外径(mm), d2管道内径(mm), L'f T型管埋藏深度计算系数, α管材的线膨胀系数(1／℃）, K为修正系数（自然升温时土对管的约束系数）, (T0一T1）为温差（℃）, Px管道内压, η曲率有关的修正系数, K0为土侧向压力系数, γ为土容重, H土埋深（m）, [σ1]管道材料的屈服极限应力, [σ2]管道材料的强度极限应力, a1准则调整系数, a2准则调整系数]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = CheckUtil.check(2, read.size(), read, titleName);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<ContinuousWeldingImportVo> dataList = new ArrayList<>();
            read.forEach(it -> {
                ContinuousWeldingImportVo entity = new ContinuousWeldingImportVo();
                entity.setVmax(new BigDecimal(it.get(0).toString()));
                entity.setAmax(new BigDecimal(it.get(1).toString()));
                entity.setDiameter(new BigDecimal(it.get(2).toString()));
                entity.setCp(new BigDecimal(it.get(3).toString()));
                entity.setCs(new BigDecimal(it.get(4).toString()));
                entity.setElasticModulus(new BigDecimal(it.get(5).toString()));
                entity.setSectionalArea(new BigDecimal(it.get(6).toString()));
                entity.setDjxs(new BigDecimal(it.get(7).toString()));
                entity.setDzbc(new BigDecimal(it.get(8).toString()));
                entity.setDzbrsj(new BigDecimal(it.get(9).toString()));
                entity.setGcbsb(new BigDecimal(it.get(10).toString()));
                entity.setTu(new BigDecimal(it.get(11).toString()));
                entity.setLj(new BigDecimal(it.get(12).toString()));
                entity.setTjyxs(new BigDecimal(it.get(13).toString()));
                entity.setD1(new BigDecimal(it.get(14).toString()));
                entity.setD2(new BigDecimal(it.get(15).toString()));
                entity.setTxgmcsdjsxs(new BigDecimal(it.get(16).toString()));
                entity.setGcdxpzxs(new BigDecimal(it.get(17).toString()));
                entity.setKxzxs(new BigDecimal(it.get(18).toString()));
                entity.setWc(new BigDecimal(it.get(19).toString()));
                entity.setPx(new BigDecimal(it.get(20).toString()));
                entity.setQlxzxs(new BigDecimal(it.get(21).toString()));
                entity.setKo(new BigDecimal(it.get(22).toString()));
                entity.setY(new BigDecimal(it.get(23).toString()));
                entity.setH(new BigDecimal(it.get(24).toString()));
                entity.setYieldLimitStress(new BigDecimal(it.get(25).toString()));
                entity.setStrengthLimitStress(new BigDecimal(it.get(26).toString()));
                entity.setA1(new BigDecimal(it.get(27).toString()));
                entity.setA2(new BigDecimal(it.get(28).toString()));
                dataList.add(entity);
            });
            return RestResponse.succeed(dataList);
        } catch (IOException e) {
            String message = "数据异常,导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse importInterfaceWelding(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            String titleName = "[E管材弹性模量（N/m^2), F管道横截面积（m^2）, L地震波长(m), Ф地震波入射角(°), V地面运动速度（m/s）, CR面波传播速度（m/s）, K地基系数（N/m^2), Cι接口形式折减系数, ι单根管段长（m）, H管道的埋深(m), D管道直径 (m), δ管壁厚度（m）, r土的重度, K0管侧横向土压力系数, η曲率有关的修正系数, μ管材泊桑比, Pn水内压（N/m^2), [△L]许用伸长(m) ]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = CheckUtil.check(2, read.size(), read, titleName);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<InterfaceWeldingImportVo> dataList = new ArrayList<>();
            read.forEach(it -> {
                InterfaceWeldingImportVo entity = new InterfaceWeldingImportVo();
                entity.setElasticModulus(new BigDecimal(it.get(0).toString()));
                entity.setSectionalArea(new BigDecimal(it.get(1).toString()));
                entity.setDzbc(new BigDecimal(it.get(2).toString()));
                entity.setDzbrsj(new BigDecimal(it.get(3).toString()));
                entity.setGroundMotionSpeed(new BigDecimal(it.get(4).toString()));
                entity.setSwPropagationVelocity(new BigDecimal(it.get(5).toString()));
                entity.setFoundationCoefficient(new BigDecimal(it.get(6).toString()));
                entity.setC1(new BigDecimal(it.get(7).toString()));
                entity.setDggdc(new BigDecimal(it.get(8).toString()));
                entity.setDepth(new BigDecimal(it.get(9).toString()));
                entity.setOutDiameter(new BigDecimal(it.get(10).toString()));
                entity.setWallThickness(new BigDecimal(it.get(11).toString()));
                entity.setTdzd(new BigDecimal(it.get(12).toString()));
                entity.setGchxtylxs(new BigDecimal(it.get(13).toString()));
                entity.setQlxzxs(new BigDecimal(it.get(14).toString()));
                entity.setGcbsb(new BigDecimal(it.get(15).toString()));
                entity.setPn(new BigDecimal(it.get(16).toString()));
                entity.setIli(new BigDecimal(it.get(17).toString()));
                dataList.add(entity);
            });
            return RestResponse.succeed(dataList);
        } catch (IOException e) {
            String message = "数据异常,导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> uploadUpNetwork(String fileIds, String versionId, String userId) throws Exception {
        Map<String, Object> map = new HashMap<>();
        shpUtils.uniformFileName(fileIds);
        ParsingResult shpData = shpUtils.getShpData(fileIds);
        //是否成功
        if (!shpData.getMessage().equals("ok")) {
            map.put("res", false);
            map.put("mess", shpData.getMessage());
        }
        List<List<Object>> shpList = shpData.getShpList();
        List<SmxUpNetworkEntity> networkList = new ArrayList<>();
        for (int i = 0; i < shpList.size(); i++) {
            String id = UUIDGenerator.getUUID();
            List<Object> list = shpList.get(i);
            if (list.size() < 68) {
                return null;
            }
            SmxUpNetworkEntity upNetworkEntity = new SmxUpNetworkEntity();
            upNetworkEntity.setDelFlag("0");
            upNetworkEntity.setId(UUIDGenerator.getUUID());
            upNetworkEntity.setTableId(id);
            upNetworkEntity.setCreateUser(userId);
            upNetworkEntity.setCreateTime(PlatformDateUtils.getCurrentDate());

            if (PlatformObjectUtils.isNotEmpty(list.get(0))) {
                upNetworkEntity.setGeom(list.get(0).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(1))) {
                upNetworkEntity.setUpId(ShpAnalyticUtil.getStringVal(list.get(1).toString(), "", false));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(2))) {
                upNetworkEntity.setName(ShpAnalyticUtil.getStringVal(list.get(2).toString(), "管道名称", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(3))) {
                upNetworkEntity.setType(ShpAnalyticUtil.getStringVal(list.get(3).toString(), "管道类型", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(4))) {
                upNetworkEntity.setStartId(ShpAnalyticUtil.getIntegerVal(list.get(4).toString(), "起点编号", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(5))) {
                upNetworkEntity.setEndId(ShpAnalyticUtil.getIntegerVal(list.get(5).toString(), "终点编号", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(6))) {
                upNetworkEntity.setLongitude(ShpAnalyticUtil.getStringVal(list.get(6).toString(), "经度", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(7))) {
                upNetworkEntity.setLatitude(ShpAnalyticUtil.getStringVal(list.get(7).toString(), "纬度", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(8))) {
                upNetworkEntity.setLength(BigDecimal.valueOf(ShpAnalyticUtil.getDoubleVal(list.get(8).toString(), "管道长度", true)));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(9))) {
                upNetworkEntity.setSiteClassification(ShpAnalyticUtil.getStringVal(list.get(9).toString(), "场地类别", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(10))) {
                upNetworkEntity.setMaterial(ShpAnalyticUtil.getStringVal(list.get(10).toString(), "管材", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(11))) {
                upNetworkEntity.setDiameter(BigDecimal.valueOf(ShpAnalyticUtil.getDoubleVal(list.get(11).toString(), "管道直径", true)));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(12))) {
                upNetworkEntity.setIntensity(ShpAnalyticUtil.getStringVal(list.get(12).toString(), "设防情况", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(13))) {
                upNetworkEntity.setYear(ShpAnalyticUtil.getIntegerVal(list.get(13).toString(), "建设年代", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(14))) {
                upNetworkEntity.setJoint(ShpAnalyticUtil.getStringVal(list.get(14).toString(), "建设年代", true));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(15))) {
                upNetworkEntity.setDisasterRate6(new BigDecimal(list.get(15).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(16))) {
                upNetworkEntity.setDisasterRate7(new BigDecimal(list.get(16).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(17))) {
                upNetworkEntity.setDisasterRate8(new BigDecimal(list.get(17).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(18))) {
                upNetworkEntity.setDisasterRate9(new BigDecimal(list.get(18).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(19))) {
                upNetworkEntity.setDisasterRate10(new BigDecimal(list.get(19).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(20))) {
                upNetworkEntity.setMaterialType(list.get(20).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(21))) {
                upNetworkEntity.setElasticityModulus(new BigDecimal(list.get(21).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(22))) {
                upNetworkEntity.setYieldLimitStress(new BigDecimal(list.get(22).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(23))) {
                upNetworkEntity.setStrengthLimitStress(new BigDecimal(list.get(23).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(24))) {
                upNetworkEntity.setPermissibleStrain(new BigDecimal(list.get(24).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(25))) {
                upNetworkEntity.setThickness(new BigDecimal(list.get(25).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(26))) {
                upNetworkEntity.setPressure(new BigDecimal(list.get(26).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(27))) {
                upNetworkEntity.setJointy(list.get(27).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(28))) {
                upNetworkEntity.setAllowableElongation(new BigDecimal(list.get(28).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(29))) {
                upNetworkEntity.setLiquefaction6(list.get(29).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(30))) {
                upNetworkEntity.setLiquefaction7(list.get(30).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(31))) {
                upNetworkEntity.setLiquefaction8(list.get(31).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(32))) {
                upNetworkEntity.setLiquefaction9(list.get(32).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(33))) {
                upNetworkEntity.setSeismicSubsidence6(list.get(33).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(34))) {
                upNetworkEntity.setSeismicSubsidence7(list.get(34).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(35))) {
                upNetworkEntity.setSeismicSubsidence8(list.get(35).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(36))) {
                upNetworkEntity.setSeismicSubsidence9(list.get(36).toString());
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(37))) {
                upNetworkEntity.setDepth(new BigDecimal(list.get(37).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(38))) {
                upNetworkEntity.setMaxSpeed(new BigDecimal(list.get(38).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(39))) {
                upNetworkEntity.setMaxAccelaration(new BigDecimal(list.get(39).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(40))) {
                upNetworkEntity.setLongitudinalWaveVelocity(new BigDecimal(list.get(40).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(41))) {
                upNetworkEntity.setTransverseWaveVelocity(new BigDecimal(list.get(41).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(42))) {
                upNetworkEntity.setCrossSectionalArea(new BigDecimal(list.get(42).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(43))) {
                upNetworkEntity.setFoundationZCoefficient(new BigDecimal(list.get(43).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(44))) {
                upNetworkEntity.setEarthquakeWavelength(new BigDecimal(list.get(44).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(45))) {
                upNetworkEntity.setEarthquakewaveIncidentAngle(new BigDecimal(list.get(45).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(46))) {
                upNetworkEntity.setPoissonsRatio(new BigDecimal(list.get(46).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(47))) {
                upNetworkEntity.setSoilbulkDensity1(new BigDecimal(list.get(47).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(48))) {
                upNetworkEntity.setBurialDepth(new BigDecimal(list.get(48).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(49))) {
                upNetworkEntity.setSoilstaticPressureCoefficient(new BigDecimal(list.get(49).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(50))) {
                upNetworkEntity.setPipeOd(new BigDecimal(list.get(50).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(51))) {
                upNetworkEntity.setInsideDiameter(new BigDecimal(list.get(51).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(52))) {
                upNetworkEntity.setTBuriedDepth(new BigDecimal(list.get(52).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(53))) {
                upNetworkEntity.setLinearExpansionCoefficient(new BigDecimal(list.get(53).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(54))) {
                upNetworkEntity.setCorrectionFactor(new BigDecimal(list.get(54).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(55))) {
                upNetworkEntity.setTemperatureDifference(new BigDecimal(list.get(55).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(56))) {
                upNetworkEntity.setInternalPressure(new BigDecimal(list.get(56).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(57))) {
                upNetworkEntity.setCurvature(new BigDecimal(list.get(57).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(58))) {
                upNetworkEntity.setSoilLateralPressure(new BigDecimal(list.get(58).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(59))) {
                upNetworkEntity.setSoilbulkDensity2(new BigDecimal(list.get(59).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(60))) {
                upNetworkEntity.setSoilBurialDepth(new BigDecimal(list.get(60).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(61))) {
                upNetworkEntity.setAdjustmentCoefficient1(new BigDecimal(list.get(61).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(62))) {
                upNetworkEntity.setAdjustmentCoefficient2(new BigDecimal(list.get(62).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(63))) {
                upNetworkEntity.setGroundMotionSpeed(new BigDecimal(list.get(63).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(64))) {
                upNetworkEntity.setSurfaceWaveVelocity(new BigDecimal(list.get(64).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(65))) {
                upNetworkEntity.setInterfaceReductionCoefficient(new BigDecimal(list.get(65).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(66))) {
                upNetworkEntity.setSinglePipeLength(new BigDecimal(list.get(66).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(67))) {
                upNetworkEntity.setSoilPressure(new BigDecimal(list.get(67).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(68))) {
                upNetworkEntity.setInternalWaterPressure(new BigDecimal(list.get(68).toString()));
            }
            if (PlatformObjectUtils.isNotEmpty(list.get(69))) {
                upNetworkEntity.setNote(list.get(69).toString());
            }
            if (list.size() > 70 && !PlatformObjectUtils.isEmpty(list.get(70))) {
                upNetworkEntity.setExtends1(list.get(70).toString());
            }
            if (list.size() > 71 && !PlatformObjectUtils.isEmpty(list.get(71))) {
                upNetworkEntity.setExtends2(list.get(71).toString());
            }
            if (list.size() > 72 && !PlatformObjectUtils.isEmpty(list.get(72))) {
                upNetworkEntity.setExtends3(list.get(72).toString());
            }
            if (list.size() > 73 && !PlatformObjectUtils.isEmpty(list.get(73))) {
                upNetworkEntity.setExtends4(list.get(73).toString());
            }
            if (list.size() > 74 && !PlatformObjectUtils.isEmpty(list.get(74))) {
                upNetworkEntity.setExtends5(list.get(74).toString());
            }
            if (list.size() > 75 && !PlatformObjectUtils.isEmpty(list.get(75))) {
                upNetworkEntity.setExtends6(list.get(75).toString());
            }
            if (list.size() > 76 && !PlatformObjectUtils.isEmpty(list.get(76))) {
                upNetworkEntity.setExtends7(list.get(76).toString());
            }
            if (list.size() > 77 && !PlatformObjectUtils.isEmpty(list.get(77))) {
                upNetworkEntity.setExtends8(list.get(77).toString());
            }
            if (list.size() > 78 && !PlatformObjectUtils.isEmpty(list.get(78))) {
                upNetworkEntity.setExtends9(list.get(78).toString());
            }
            if (list.size() > 79 && !PlatformObjectUtils.isEmpty(list.get(79))) {
                upNetworkEntity.setExtends10(list.get(79).toString());
            }
            upNetworkEntity.setVersionId(versionId);
            networkList.add(upNetworkEntity);

            SmxMainTableEntity mainEntity = new SmxMainTableEntity();
            mainEntity.setId(id);
            mainEntity.setCreateUser(userId);
            mainEntity.setYear(upNetworkEntity.getYear());
            mainEntity.setVersionId(versionId);
            mainEntity.setFortification(upNetworkEntity.getIntensity());
            mainEntity.setBusinessObject(FxfzConstants.CZT_SMX_DXGW);
            mainTableUtils.saveMainTable(mainEntity);
        }
        boolean res = false;

        int i = 1;
        for (SmxUpNetworkEntity entity : networkList) {
            entity.setSerialNumber(i);
            res = upNetworkRepository.saveUpNetWork(entity);
            i += 1;
        }
        map.put("res", res);
        return map;
    }

    @Override
    public HashMap<Integer, ArrayList<String>> getDataValidation(String versionId, Integer type) {
        HashMap<Integer, ArrayList<String>> map = new HashMap<>();
        SmxVersionEntity versionEntity = lifelineEngineeringRepository.getById(versionId);
        if (PlatformObjectUtils.isNotEmpty(versionEntity)) {
            List<SmxUpNetworkEntity> networkList = upNetworkRepository.getByVersionId(versionEntity.getId());
            for (SmxUpNetworkEntity entity : networkList) {
                ArrayList<String> list = new ArrayList<>();
                if (type == 1) {
                    DataValidation1Dto dto = new DataValidation1Dto();
                    BeanUtils.copyProperties(entity, dto);
                    list = ValidationProcessor.validate(dto);
                }
                if (type == 2) {
                    DataValidation2Dto dto = new DataValidation2Dto();
                    BeanUtils.copyProperties(entity, dto);
                    list = ValidationProcessor.validate(dto);
                }
                if (type == 3) {
                    DataValidation2Dto dto = new DataValidation2Dto();
                    BeanUtils.copyProperties(entity, dto);
                    list = ValidationProcessor.validate(dto);
                }
                if (list.size() != 0) {
                    map.put(entity.getSerialNumber(), list);
                }
            }
        }
        return map;
    }

    @Override
    public SmxUpNetworkEntity getByTableId(String id) {
        return upNetworkRepository.getByTableId(id);
    }

    @Override
    public void updateSimpleModelById(UpNetwork1Param network1Param) {
        upNetworkRepository.updateSimpleModelById(network1Param);
    }

    @Override
    public void updateContinuousWeldingById(UpNetwork2Param network2Param) {
        upNetworkRepository.updateContinuousWeldingById(network2Param);
    }

    @Override
    public void updateInterfaceTypeById(UpNetwork3Param network3Param) {
        upNetworkRepository.updateInterfaceTypeById(network3Param);
    }

    @Override
    public UpNetwork1Param countSimpleModel(UpNetwork1Param param) {
        param.setDisasterRate6State(getDestructiveState(param.getDisasterRate6()));
        param.setDisasterRate7State(getDestructiveState(param.getDisasterRate7()));
        param.setDisasterRate8State(getDestructiveState(param.getDisasterRate8()));
        param.setDisasterRate9State(getDestructiveState(param.getDisasterRate9()));
        param.setDisasterRate10State(getDestructiveState(param.getDisasterRate10()));
        return param;
    }

    @Override
    public RestResponse continuousCount(UpNetwork2Param param) {
        //表格1   最大管线应变
        BigDecimal result1 = param.getMaxSpeed().divide(param.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                .add(param.getMaxAccelaration().multiply(param.getDiameter()).divide(BigDecimal.valueOf(2)
                        .multiply(param.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

        BigDecimal result2 = param.getMaxSpeed().negate().divide(param.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                .add(param.getMaxAccelaration().multiply(param.getDiameter()).divide(BigDecimal.valueOf(2)
                        .multiply(param.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

        BigDecimal result3 = param.getMaxSpeed().divide(param.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                .subtract(param.getMaxAccelaration().multiply(param.getDiameter()).divide(BigDecimal.valueOf(2)
                        .multiply(param.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

        BigDecimal result4 = param.getMaxSpeed().negate().divide(param.getLongitudinalWaveVelocity(), 4, RoundingMode.HALF_UP)
                .subtract(param.getMaxAccelaration().multiply(param.getDiameter()).divide(BigDecimal.valueOf(2)
                        .multiply(param.getTransverseWaveVelocity().pow(2)), 4, RoundingMode.HALF_UP));

        ArrayList<BigDecimal> list = new ArrayList<>();
        list.add(result1);
        list.add(result2);
        list.add(result3);
        list.add(result4);
        param.setMaxPipelineStrain(list.stream().filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(new BigDecimal(0)));

        //表格2   l'
        BigDecimal cos = BigDecimal.valueOf(Math.cos(Math.toRadians(param.getEarthquakewaveIncidentAngle().doubleValue()))).setScale(4, RoundingMode.HALF_UP);
        BigDecimal lCos = param.getEarthquakeWavelength().divide(cos, 4, RoundingMode.HALF_UP);
        param.setLCos(lCos);

        //s
        BigDecimal s = BigDecimal.valueOf(1).divide(BigDecimal.valueOf(1).add(param.getElasticityModulus().multiply(param.getCrossSectionalArea()).divide(param.getFoundationZCoefficient(), 4, BigDecimal.ROUND_HALF_UP)
                .multiply(BigDecimal.valueOf(2).multiply(BigDecimal.valueOf(Math.PI))
                        .divide(param.getLCos(), 4, RoundingMode.HALF_UP).pow(2))), 4, RoundingMode.HALF_UP);
        param.setS(s);

        //ep
        BigDecimal ep = param.getMaxPipelineStrain().multiply(param.getS()).setScale(4, RoundingMode.HALF_UP);
        param.setEp(ep);

        //zdyl
        BigDecimal zdyl = param.getEp().multiply(param.getElasticityModulus()).setScale(4, RoundingMode.HALF_UP);
        param.setZdyl(zdyl);

        //表格3   //弯曲段产生的剪力
        BigDecimal wqdcsdjl = param.getMaxPipelineStrain().multiply(param.getElasticityModulus()).subtract(param.getSoilbulkDensity1()).multiply(param.getBurialDepth()).setScale(4, RoundingMode.HALF_UP);
        param.setWqdcsdjl(wqdcsdjl);

        //弯矩
        BigDecimal wj = param.getWqdcsdjl().divide((new BigDecimal(3).multiply(param.getSoilstaticPressureCoefficient())), 4, RoundingMode.HALF_UP);
        param.setWj(wj);

        //i
        BigDecimal i = param.getPipeOd().divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
        param.setI(i);

        //ipai
        BigDecimal ipai = BigDecimal.valueOf(Math.PI).multiply(param.getPipeOd().pow(4)).divide(BigDecimal.valueOf(64), 4, RoundingMode.HALF_UP)
                .subtract(BigDecimal.valueOf(Math.PI).multiply(param.getInsideDiameter().pow(4)).divide(BigDecimal.valueOf(64), 4, RoundingMode.HALF_UP));

        if (ipai.compareTo(new BigDecimal(0)) == 0) {
            return RestResponse.fail("{d1 管道外径}和{d2 管道内径}的值不能相等!");
        }
        param.setIpai(ipai);

        //弯曲段弯曲应力（轴向）
        BigDecimal wqylZx = param.getI().multiply((param.getWj()).divide(param.getIpai(), 4, RoundingMode.HALF_UP));
        param.setWqylZx(wqylZx);

        //弯曲段的剪应力（环向）
        BigDecimal jylHx = param.getWqdcsdjl().divide(param.getCrossSectionalArea(), 4, RoundingMode.HALF_UP);
        param.setJylHx(jylHx);

        //表格4   T型接头处产生的剪力Q
        BigDecimal txjtcjyl = param.getMaxPipelineStrain().multiply(param.getElasticityModulus()).multiply(param.getCrossSectionalArea())
                .subtract(param.getSoilbulkDensity1()).multiply(param.getTBuriedDepth()).setScale(4, RoundingMode.HALF_UP);
        param.setTxjtcjyl(txjtcjyl.divide(BigDecimal.valueOf(2), 4, RoundingMode.HALF_UP));

        //弯矩M
        BigDecimal wjT = param.getTxjtcjyl().divide((new BigDecimal(2)).multiply(param.getSoilstaticPressureCoefficient()), 4, RoundingMode.HALF_UP);
        param.setWjT(wjT);

        //T型段的正应力（轴向）
        BigDecimal zylZxT = param.getWjT().multiply(param.getDiameter()).divide((new BigDecimal(2).multiply(param.getIpai())), 4, RoundingMode.HALF_UP);
        param.setZylZxT(zylZxT);

        //T型段的剪应力（环向）
        BigDecimal jylHxT = param.getTxjtcjyl().divide(param.getCrossSectionalArea(), 4, RoundingMode.HALF_UP);
        param.setJylHxT(jylHxT);

        //表格5   温度引起的温度应力
        BigDecimal wdyl = param.getElasticityModulus().multiply(param.getLinearExpansionCoefficient()).multiply(param.getCorrectionFactor()).multiply(param.getTemperatureDifference()).setScale(4, BigDecimal.ROUND_HALF_UP);
        param.setWdyl(wdyl);

        //表格6    环向拉应力
        //管壁厚度  （d1-d2）/2
        BigDecimal wallThickness = (param.getPipeOd().subtract(param.getInsideDiameter())).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
        param.setWallThickness(wallThickness);

        BigDecimal hxlyl = param.getInternalPressure().multiply(param.getDiameter()).divide((new BigDecimal(2).multiply(param.getWallThickness())), 4, RoundingMode.HALF_UP);
        param.setHxlyl(hxlyl);

        //纵向拉应力
        BigDecimal zxlyl = (param.getDiameter().multiply(param.getInternalPressure()).divide((new BigDecimal(2)
                .multiply(param.getWallThickness())), 4, RoundingMode.HALF_UP)).multiply(param.getCurvature());
        param.setZxlyl(zxlyl);

        //表格7  土静压力
        BigDecimal ps = (new BigDecimal(1).add(param.getSoilLateralPressure())).multiply(param.getSoilbulkDensity2()).multiply(param.getSoilBurialDepth()).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP);
        param.setPs(ps);


        //环向压应力
        BigDecimal hxyyl = param.getPs().multiply(param.getDiameter()).divide((new BigDecimal(2).multiply(param.getWallThickness())), 4, RoundingMode.HALF_UP);
        param.setHxyyl(hxyyl);

        //纵向压应力
        BigDecimal zxyyl = param.getPoissonsRatio().multiply(param.getHxyyl()).setScale(4, RoundingMode.HALF_UP);
        param.setZxyyl(zxyyl);

        //表格8   所有轴向应力之和a1
        BigDecimal allSumZx = param.getEp().add(param.getWqylZx()).add(param.getZylZxT()).add(param.getZxyyl()).add(param.getWdyl().add(param.getZxlyl())).setScale(4, BigDecimal.ROUND_HALF_UP);
        param.setAllSumZx(allSumZx);

        //表格9  所有轴向应力之和a2
        BigDecimal allSumHx = param.getJylHx().add(param.getJylHxT()).add(param.getHxlyl()).add(param.getHxyyl()).setScale(4, RoundingMode.HALF_UP);
        param.setAllSumHx(allSumHx);

        //表格10   许用应力
        BigDecimal subtract = param.getAllSumZx().subtract(param.getAllSumHx());
        BigDecimal permissibleStress = BigDecimal.valueOf(Math.abs(subtract.doubleValue()));
        param.setPermissibleTress(permissibleStress);

        if (PlatformObjectUtils.isEmpty(param.getPermissibleTressCorrect())) {
            param.setPermissibleTressCorrect(permissibleStress);
        }

        BigDecimal ar = param.getYieldLimitStress().multiply(param.getAdjustmentCoefficient1());
        BigDecimal ab = param.getStrengthLimitStress().multiply(param.getAdjustmentCoefficient2());

        if (param.getPermissibleTress().compareTo(ar) < 0) {
            param.setLxBreakState("基本完好");
            param.setLxBreakStateCorrect("基本完好");
        } else if (ar.compareTo(param.getPermissibleTress()) < 0 || ar.compareTo(param.getPermissibleTress()) == 0
                && param.getPermissibleTress().compareTo(ab) < 0 || param.getPermissibleTress().compareTo(ab) == 0) {
            param.setLxBreakState("中等破坏");
            param.setLxBreakStateCorrect("中等破坏");
        } else if (param.getPermissibleTress().compareTo(ab) > 0) {
            param.setLxBreakState("破坏");
            param.setLxBreakStateCorrect("破坏");
        }

        if (param.getPermissibleTressCorrect().compareTo(ar) < 0) {
            param.setLxBreakStateCorrect("基本完好");
        } else if (ar.compareTo(param.getPermissibleTressCorrect()) < 0 || ar.compareTo(param.getPermissibleTressCorrect()) == 0
                && param.getPermissibleTressCorrect().compareTo(ab) < 0 || param.getPermissibleTressCorrect().compareTo(ab) == 0) {
            param.setLxBreakStateCorrect("中等破坏");
        } else if (param.getPermissibleTressCorrect().compareTo(ab) > 0) {
            param.setLxBreakStateCorrect("破坏");
        }
        return RestResponse.succeed(param);
    }

    @Override
    public RestResponse interfaceCount(UpNetwork3Param param) {
        //表格1
        BigDecimal lcos = param.getEarthquakeWavelength().divide(BigDecimal.valueOf(Math.cos(Math.toRadians(param.getEarthquakewaveIncidentAngle().doubleValue()))), 4, RoundingMode.HALF_UP);

        param.setJkLCos(lcos);


        BigDecimal result = BigDecimal.valueOf(1).divide(BigDecimal.valueOf(1).add(param.getElasticityModulus().multiply(param.getCrossSectionalArea())
                .divide(param.getFoundationZCoefficient(), 4, RoundingMode.HALF_UP)
                .multiply(BigDecimal.valueOf(2).multiply(BigDecimal.valueOf(Math.PI)).divide(param.getJkLCos(), 4, RoundingMode.HALF_UP).pow(2))), 4, RoundingMode.HALF_UP);

        param.setResult(result);

        //ER
        BigDecimal er = param.getGroundMotionSpeed().divide(param.getSurfaceWaveVelocity(), 4, RoundingMode.HALF_UP);
        param.setEr(er);

        //管道轴向应变量幅值
        BigDecimal et = param.getEr().multiply(result);
        param.setEt(et);

        //LT
        BigDecimal lt = param.getInterfaceReductionCoefficient().multiply(param.getSinglePipeLength()).multiply(param.getEt());
        param.setLt(lt);


        //表格2  ps
        BigDecimal ps = (new BigDecimal(1).add(param.getSoilPressure())).divide(new BigDecimal(2), 4, RoundingMode.HALF_UP).multiply(param.getSoilbulkDensity2()).multiply(param.getDepth()).setScale(4, RoundingMode.HALF_UP);
        param.setJkPs(ps);

        //es
        BigDecimal es = (param.getJkPs().multiply(param.getPipeOd()).multiply(param.getCurvature())).divide((new BigDecimal(2)).multiply(param.getSoilbulkDensity2()), 4, RoundingMode.HALF_UP).multiply((new BigDecimal(1).divide(param.getElasticityModulus(), 4, RoundingMode.HALF_UP)));
        param.setEs(es);

        //压缩变形
        BigDecimal compressDeform = param.getEs().multiply(param.getSinglePipeLength()).setScale(4, RoundingMode.HALF_UP);
        param.setCompressDeform(compressDeform);

        //表格3    拉伸应变
        BigDecimal tensileStrain = (param.getInternalWaterPressure().multiply(param.getPipeOd()).multiply(param.getCurvature())).
                divide(new BigDecimal(2).multiply(param.getThickness()), 4, RoundingMode.HALF_UP).multiply((new BigDecimal(1).divide(param.getElasticityModulus(), 4, RoundingMode.HALF_UP))).setScale(4, RoundingMode.HALF_UP);
        param.setTensileStrain(tensileStrain);

        //拉伸变形
        BigDecimal strainDeform = param.getTensileStrain().multiply(param.getSinglePipeLength()).setScale(4, RoundingMode.HALF_UP);
        param.setStrainDeform(strainDeform);

        //组合轴向拉伸
        BigDecimal combineAxialStrain = param.getLt().add(param.getCompressDeform()).add(param.getStrainDeform()).setScale(4, RoundingMode.HALF_UP);
        param.setCombineAxialStrain(combineAxialStrain);

        if (PlatformObjectUtils.isEmpty(param.getCombineAxialStrainCorrect())) {
            param.setCombineAxialStrainCorrect(combineAxialStrain);
        }

        BigDecimal val = param.getAllowableElongation();
        if (combineAxialStrain.compareTo(val) < 0) {
            param.setJkDamage("轻微破坏");
        } else {
            int i = combineAxialStrain.compareTo(new BigDecimal(2).multiply(val));
            if (val.compareTo(combineAxialStrain) < 0
                    && i < 0) {
                param.setJkDamage("中等破坏");
            } else if (i > 0) {
                param.setJkDamage("破坏");
            }
        }

        BigDecimal combineAxialStrainCorrect = param.getCombineAxialStrainCorrect();
        if (combineAxialStrainCorrect.compareTo(val) < 0) {
            param.setJkDamageCorrect("轻微破坏");
        } else {
            int i = combineAxialStrainCorrect.compareTo(new BigDecimal(2).multiply(val));
            if (val.compareTo(combineAxialStrainCorrect) < 0
                    && i < 0) {
                param.setJkDamageCorrect("中等破坏");
            } else if (i > 0) {
                param.setJkDamageCorrect("破坏");
            }
        }
        return RestResponse.succeed(param);
    }
}
